import { delOrderPointApi } from "@/api/waybillManagement/workOrder";
import { Modal, message } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { createVNode } from "vue";

export default function OperationHook(state: Base.GeneraDataType) {
  const { dialogOpts, emit } = state;
  // 修改更新进度
  const modifyTrackInfoHandle = (row: Base.GeneraDataType) => {
    dialogOpts.width = "520px";
    dialogOpts.title = "更新进度";
    dialogOpts.passData = row;
    dialogOpts.type = 2;
    dialogOpts.component = "UploadFile";
    dialogOpts.visible = true;
  };
  //删除
  const deleteHandle = (row: Base.GeneraDataType) => {
    Modal.confirm({
      title: "是否删除进度?",
      icon: createVNode(ExclamationCircleOutlined),
      content: "",
      okText: "确定",
      okType: "danger",
      cancelText: "取消",
      onOk() {
        delOrderPointApi(row.id).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("操作成功!");
            emit("submit");
          }
        });
      }
    });
  };

  const dialogSubmitHandle = () => {
    dialogOpts.visible = false;
    emit("submit");
  };

  return {
    modifyTrackInfoHandle,
    dialogSubmitHandle,
    deleteHandle
  };
}
